// ValidationAspects
// Written by Mike Saunders
// Released under Microsoft Public License (Ms-PL)
using System;
using ValidationAspects.Sdk;

namespace ValidationAspects.Exceptions
{
	public class ValidateObjectException : ValidationException
	{
		public static Func<ValidateObjectException, string> MessageFormat { get; set; }

		static ValidateObjectException()
		{
			ResetMessageFormat();
		}

		public ValidateObjectException(object instance)
		{
			Enforce.IsNotNull(instance, "instance");
			Object = instance;
		}

		public static void ResetMessageFormat()
		{
			MessageFormat = e => string.Format("Object [type:{0}] failed validation.", e.Object.GetType());
		}

		public override string Message
		{
			get { return MessageFormat(this); }
		}

		public object Object { get; private set; }
	}
}